function [ EC ] = APEaddEmptyFooter( datasetname )
%[ EC ] = APEaddEmptyFooter( datasetname )
%
%   adds an empty FOOTER structure to a APE MAT file. NEcessary e.g. when
%   converting from ASC to MAT and ther is no metadata available.
%
% INPUT     datasetname :   File to process (*.mat)
% OUTPUT    EC          :   error code (0 = success, 1 = error)


%  (c) F. Dworkowski, 2012
%      Version 1.0, 2012-06-20

% DEPENDENCIES:     none, but should be updated according to header in
%                   loadsif_nongui and loadsif3!

if nargin < 1
    help APEaddEmptyFooter;
    EC = 1;
    return
end

try dset=load(datasetname);
catch ME
  errordlg('ERROR: file not found in "APEmat2asc"!')
      EC = 1;
  return
end

footer = addfooter(datasetname);
 % UPDATE: FOOTER is now a STRUCT constuct instead of a CHAR array:
    dset.footer = cell2struct(footer(:,2), footer(:,1),1);

save(datasetname,'-struct','dset')
EC = 0;


function header = addfooter(datasetname)
% adds empty footer with exception that DATASETNAME is used as filename(22)

    header = cell(21,2);
    header(1,:)={'FormattedTime', ''};
    header(2,:)={'SWVersionEx', ''};
    header(3,:)={'Temperature', ''};
    header(4,:)={'HeadModel', ''};
    header(5,:)={'Operation', ''};
    header(6,:)={'ModeFullName', ''};
    header(7,:)={'TriggerSourceFullName', ''};
    header(8,:)={'ExposureTime', ''};
    header(9,:)={'IntegrationCycleTime', ''};
    header(10,:)={'NumberIntegrations', ''};
    header(11,:)={'KineticCycleTime', ''};
    header(12,:)={'Frequency', ''};
    header(13,:)={'NumberImages', ''};
    header(14,:)={'ReadPatternFullName', ''};
    header(15,:)={'VerticalShiftSpeed', ''};
    header(16,:)={'PixelReadOutTime', ''};           % Hz?
    header(17,:)={'BaselineClamp', ''};                   % Baseline Clamp?
    header(18,:)={'VerticalClockAmp', ''};           % ClockAmp?
    header(19,:)={'OutputAmplifier', ''};
    header(20,:)={'Serial', ''};
    header(21,:)={'PreAmplifierGain', ''};
    header(22,:)={'FileName', datasetname};
    % header(23,:)={'Wavelength', 23);        % ???
    %  header(24,:)={'Filter', 24);
    %  header(25,:)={'GratingBlaze', 25);
    % header(26,:)={'Filter', 26);
    % header(27,:)={'Slit', 27);

end

end